<?php

$name = $_POST['nameG'];
$mess = $_POST['messG'];
$creator = $_COOKIE["loggedIn"];
$player1 = $_POST['player1G'];
$player2 = $_POST['player2G'];
$player3 = $_POST['player3G'];

$hostDB = "localhost";
$userDB = "ampersand";
$passDB = "palomitas";
$dbnameDB = "LYONUNO";

$canalDB = mysql_connect($hostDB, $userDB, $passDB);
$db = mysql_select_db($dbnameDB);

$pub = 'n';

$priv = $_POST['privateG'];

if ($priv != "on"){
	$pub = 'y';
	$player1 = '';
	$player2 = '';
	$player3 = '';
}
$sentencia = "INSERT INTO GAME values('{$name}','{$mess}','{$pub}','{$creator}', 'y','{$player1}', 'n','{$player2}', 'n','{$player3}', 'n')";

if($name != '')
	$res = mysql_db_query($dbnameDB, $sentencia,$canalDB);

mysql_db_query($dbnameDB, "commit",$canalDB);

mysql_close($canalDB);

if ($res == 1){
	header('Location: /waiting.php?game='.$name);
} else
	header('Location: /main.php?page=existingGame.html');
?>

